package com.techstar.ats.codec.live.decoder;

import io.netty.buffer.ByteBuf;
import com.techstar.ats.codec.Decoder;
import com.techstar.ats.dxp.live.DeviceStatus;
import com.techstar.ats.dxp.live.F04DeviceStatusBitmapType;
import com.techstar.ats.type.DeviceType;

public enum F04DeviceStatusBitmapTypeDecoder implements Decoder<F04DeviceStatusBitmapType> {
	INSTANCE;

	public F04DeviceStatusBitmapType create() {
		return new F04DeviceStatusBitmapType();
	}

	public void decode(ByteBuf buf, F04DeviceStatusBitmapType value) {
		value.devType = DeviceType.valueOf(buf.readUnsignedShort());
		int cnt = buf.readUnsignedShort();

		for(int i = 0; i < cnt; ++i) {
			DeviceStatus device = DeviceStatusDecoder.INSTANCE.create();
			device.type = value.devType;
			DeviceStatusDecoder.INSTANCE.decode(buf, device);
			value.devices.add(device);
		}

	}
}
